package com.thalesgroup.nl.trtdelft.dein.mapper.example;

import com.thalesgroup.nl.trtdelft.dein.mapper.AbstractMappedWebService;
import com.thalesgroup.nl.trtdelft.dein.servlet.impl.Client;
import java.io.IOException;
import java.io.Serializable;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.http.HttpException;
import org.json.simple.JSONObject;

/**
 *
 * @author AbdelhaqA
 */
public class YahooRestaurantService extends AbstractMappedWebService {

    @Override
    @SuppressWarnings("unchecked")
    public void input(String senderAddress, String inputVariableName, Serializable input) {

    }

    @Override
    public void start() {           
        JSONObject args = new JSONObject();
        String coord = (String) queryReceiveVariableContent.get("gpsRestaurant");
        String longitude = "139.72756755";
        String latitude ="35.66282728";
        try {
            String restaurantInfo = Client.get("http://api.gnavi.co.jp/ver2/RestSearchAPI/?keyid=7ec8fb229d8f7dba6847de2f569a38ea&input_coordinates_mode=2&longitude="+longitude+"&latitude="+latitude+"&sort=1&range=3&lang=en&hit_per_page=10", args.toJSONString());
            if (restaurantInfo != null)
            outputs.put("listOfRestaurants", restaurantInfo); 
        //    sendMapperInformationInterface.sendOutput();
        } catch (HttpException ex) {
            Logger.getLogger(YahooRestaurantService.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(YahooRestaurantService.class.getName()).log(Level.SEVERE, null, ex);
        } catch (URISyntaxException ex) {
            Logger.getLogger(YahooRestaurantService.class.getName()).log(Level.SEVERE, null, ex);
        }         
    }
    @Override
    public void computeOutput(String variableName) throws IllegalStateException {
        computeOutput();
    }

    @Override
    public Serializable getCurrentOutput(String variableName) throws IllegalStateException {
        return outputs.get(variableName);
    }

}
